package com.it2297.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;

import com.it2297.controller.ProductController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;

public class PieChartView extends JDialog {
	private ProductController pc = new ProductController(this);
	private final JPanel contentPanel = new JPanel();
	private final JScrollPane scrollPane = new JScrollPane();

	public PieChartView() {
		setBounds(100, 100, 750, 550);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		scrollPane.setBounds(0, 0, 750, 550);
		
		contentPanel.add(scrollPane);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("Send");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						//BufferedImage bi = pc.createImage(pc.panel);
						Image img = pc.bufferedImagetoImage(pc.createImage(pc.panel));
						/*boolean success = pc.sendImgEmail(img);
						if(success){
							close();
						}
						*/
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						close();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
	
	public void setPanel(JPanel panel) {
		getScrollpane().setViewportView(panel);
	}

	public JScrollPane getScrollpane() {
		return scrollPane;
	}
	public void close(){
		this.dispose();
	}
}
